﻿package com.mui.controls
{
    import com.gengine.global.*;
    import com.mui.manager.*;
    import com.mui.skins.*;
    import com.mui.utils.*;
    import fl.controls.*;
    import fl.core.*;
    import fl.managers.*;
    import flash.display.*;
    import flash.events.*;

    public class GComboBox extends ComboBox implements IToolTipItem, IFrUI
    {
        public const CLASSNAME:String = "ComboBox";
        private var _isDisposed:Boolean;
        private var _toolTipData:Object;
        private var _reactionTime:int = 500;
        private var _styleName:String;
        private var _isStyleChange:Boolean = false;

        public function GComboBox()
        {
            this.tabChildren = false;
            this._styleName = this.CLASSNAME;
            this.addEventListener(Event.ADDED_TO_STAGE, this.judgeToolTip);
            this.addEventListener(Event.REMOVED_FROM_STAGE, this.judgeToolTip);
            return;
        }// end function

        override protected function focusOutHandler(event:FocusEvent) : void
        {
            isKeyDown = false;
            if (isOpen)
            {
                if ((!event.relatedObject || !list.contains(event.relatedObject)) && event.target is  == false)
                {
                    if (highlightedCell != -1 && highlightedCell != selectedIndex)
                    {
                        selectedIndex = highlightedCell;
                        dispatchEvent(new Event(Event.CHANGE));
                    }
                    close();
                }
            }
            if (isOurFocus(event.target as DisplayObject))
            {
                drawFocus(false);
                isFocused = false;
            }
            return;
        }// end function

        protected function judgeToolTip(event:Event = null) : void
        {
            if (event && event.type == Event.ADDED_TO_STAGE && this.toolTipData || !event && this.toolTipData && Global.stage.contains(this))
            {
                ToolTipsManager.register(this);
            }
            else
            {
                ToolTipsManager.unregister(this);
            }
            return;
        }// end function

        public function get toolTipData()
        {
            return this._toolTipData;
        }// end function

        public function set toolTipData(param1) : void
        {
            this._toolTipData = param1;
            this.judgeToolTip();
            return;
        }// end function

        public function get reactionTime() : int
        {
            return this._reactionTime;
        }// end function

        public function set reactionTime(param1:int) : void
        {
            this._reactionTime = param1;
            return;
        }// end function

        public function configEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
        {
            ObjEventListerTool.addObjEvent(this, param1, param2, param3);
            addEventListener(param1, param2, param3, param4, param5);
            return;
        }// end function

        public function set isDisposed(param1:Boolean) : void
        {
            this._isDisposed = param1;
            return;
        }// end function

        override public function removeEventListener(param1:String, param2:Function, param3:Boolean = false) : void
        {
            ObjEventListerTool.removeObjEvent(this, param1, param2, param3);
            super.removeEventListener(param1, param2, param3);
            return;
        }// end function

        final override protected function configUI() : void
        {
            super.configUI();
            this.createChildren();
            return;
        }// end function

        public function get styleName() : String
        {
            return this._styleName;
        }// end function

        public function set styleName(param1:String) : void
        {
            if (this._styleName != param1)
            {
                this._styleName = param1;
                invalidate(InvalidationType.STYLES);
                this._isStyleChange = true;
            }
            return;
        }// end function

        final override protected function draw() : void
        {
            if (isInvalid(InvalidationType.STYLES))
            {
                if (this._isStyleChange)
                {
                    SkinManager.setComponentStyle(this, this._styleName);
                    this._isStyleChange = false;
                }
                this.updateStyle();
            }
            if (isInvalid(InvalidationType.DATA))
            {
                this.updateDate();
            }
            if (isInvalid(InvalidationType.SIZE))
            {
                this.updateSize();
            }
            if (isInvalid(InvalidationType.SIZE, InvalidationType.SELECTED, InvalidationType.DATA))
            {
                this.updateDisplayList();
            }
            try
            {
                super.draw();
            }
            catch (e:Error)
            {
            }
            return;
        }// end function

        protected function createChildren() : void
        {
            return;
        }// end function

        protected function updateStyle() : void
        {
            return;
        }// end function

        protected function updateSize() : void
        {
            return;
        }// end function

        protected function updateDate() : void
        {
            return;
        }// end function

        protected function updateDisplayList() : void
        {
            return;
        }// end function

        override protected function focusInHandler(event:FocusEvent) : void
        {
            var _loc_2:IFocusManager = null;
            if (isOurFocus(event.target as DisplayObject))
            {
                _loc_2 = focusManager;
                if (_loc_2 && _loc_2.showFocusIndicator)
                {
                    drawFocus(true);
                    isFocused = true;
                }
            }
            return;
        }// end function

        public function set textColor(param1:uint) : void
        {
            this.textField.textField.textColor = param1;
            return;
        }// end function

        override public function set text(param1:String) : void
        {
            inputField.text = param1;
            editableValue = inputField.text;
            return;
        }// end function

        public function dispose(param1:Boolean = true) : void
        {
            if (this._isDisposed && param1)
            {
                if (Global.isDebugModle)
                {
                    Alert.show("存在组件二次释放" + this.toString());
                }
                return;
            }
            this.removeAll();
            this.editable = false;
            ObjEventListerTool.delObjEvent(this);
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            if (param1)
            {
                UICompomentPool.disposeUICompoment(this);
            }
            this._reactionTime = 500;
            return;
        }// end function

    }
}
